//
//  Converter.swift
//  foreign_swift
//
//  Created by 黄敦仁 on 15/5/18.
//  Copyright (c) 2015年 hdr. All rights reserved.
//

import Foundation

class Converter{
    
    class func rsToUser(rs:SQLiteResultSet)->User{
        let user = User()
        
        user.userId = rs.getInt("userId")
        user.email = rs.getString("email")
        user.serverId = rs.getInt64("serverId")
        user.height = rs.getInt("height")
        let ns_date = rs.getDate("birthday")
        user.birthday = Date(ns_date.timeIntervalSinceReferenceDate)
        user.nickName = rs.getString("nickName")
        user.accountName = rs.getString("accountName")
        user.avatar = rs.getString("avatar")
        user.gender = rs.getInt("gender")
        user.userType = rs.getInt("userType")
        
        return user
    }
    
    class func jsonToUser(data:JSON)->User{
        let user = User()
        
        user.email = data["email"].stringValue
        user.gender = data["gender"].integerValue
        user.height = data["height"].integerValue
        user.birthday =  Date(data["birthday"].stringValue!,dateFormat:"yyyy-MM-dd")
        user.serverId = data["id"].longLongValue
        user.accountName = data["account_name"].stringValue
        user.avatar = data["avatar_url"].stringValue
        user.nickName = data["nick_name"].stringValue
        
        return user
    }
}